//
//  TLAlterView.m
//  WXReader
//
//  Created by huaya on 2025/3/26.
//  Copyright © 2025 Andrew. All rights reserved.
//

#import "TLAlterView.h"

@interface TLAlterView ()
@property (weak, nonatomic) IBOutlet UILabel *titleLAb;
@property (weak, nonatomic) IBOutlet UIView *contentView;
@property (weak, nonatomic) IBOutlet UIView *bgView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *centerConst;
@property (weak, nonatomic) IBOutlet UIButton *leftBtn;
@property (weak, nonatomic) IBOutlet UIButton *rightBtn;

@end

@implementation TLAlterView

+ (instancetype)createView {
    return [[[NSBundle mainBundle] loadNibNamed:@"TLAlterView" owner:nil options:nil] lastObject];
}
- (IBAction)confirmAction:(id)sender {
    
    if (self.leftBtnBlock) {
        self.leftBtnBlock();
    }
    [self hidAction];
}
- (IBAction)cancelAction:(id)sender {
    
    if (self.rightBtnBlock) {
        self.rightBtnBlock();
    }
    [self hidAction];
}

- (void)awakeFromNib{
    [super awakeFromNib];
    
    self.contentView.layer.cornerRadius = 8;
    self.centerConst.constant = kScreenHeight/2+162/2;
    [self.bgView setBackgroundColor:[UIColor colorWithWhite:0 alpha:0]];
    self.rightBtn.layer.cornerRadius = 47/2;
    [self layoutIfNeeded];
    
}
- (void)showActionWithTitle:(NSString *)title andLeftBtnTitle:(NSString *)leftBtnTitle andRightBtnTitle:(NSString*)rightBtnTitle{
    
    [self.leftBtn setTitle:leftBtnTitle forState:UIControlStateNormal];
    [self.rightBtn setTitle:rightBtnTitle forState:UIControlStateNormal];
    
    self.titleLAb.text = title;
    
    [kMainWindow addSubview:self];
    [self mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(kMainWindow);
    }];
    
    [UIView animateWithDuration:0.5 animations:^{
          
        [self.bgView setBackgroundColor:[UIColor colorWithWhite:0 alpha:0.5]];
        
        self.centerConst.constant = 0;
        
        [self layoutIfNeeded];
    }];
    
}
- (void)hidAction{
    
    [UIView animateWithDuration:0.5 animations:^{
          
        [self.bgView setBackgroundColor:[UIColor colorWithWhite:0 alpha:0]];
        
        self.centerConst.constant = kScreenHeight/2+162/2;
        
        [self layoutIfNeeded];
    }completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
    
}
@end
